<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #box {
            position: absolute;
            width: 100px;
            height: 100px;
            background-color: yellow;
        }
    </style>
</head>

<body>
    <button id="btn">缓动奔跑吧</button>
    <div id="box"></div>
    <script>
    var box = document.getElementById("box");
    var timer = null;
    document.getElementById("btn").onclick = function () {
        clearInterval(timer);
        timer = setInterval(function () {
            //step = (target - leader) / 10
            //leader = leader + step
            var leader = box.offsetLeft;
            var target = 400;
            var step = (target - leader) / 10;
            step = Math.ceil(step);
            leader = leader + step;
            console.log("target: " + target + "leader: " + leader + "step: " + step);
            if (leader != target) {
                box.style.left = leader + "px";
            } else {
                clearInterval(timer);
            }
        }, 15)
    }
</script>
</body>

</html>